package com.ruibang.glass.quality.controller;

import com.ruibang.glass.quality.domain.req.DefectGroupReq;
import com.ruibang.glass.quality.entity.DefectGroup;
import com.ruibang.glass.quality.service.DefectGroupService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Author: songJinKang
 * @CreateTime: 2023-08-30  14:39
 * @Description: TODO:缺陷组
 * @Version: 1.0
 */

@RestController
@RequestMapping("/api/defect/group")
@Api(value = "缺陷组控制器", tags = {"缺陷组控制器"})
public class DefectGroupController {

    @Autowired
    private DefectGroupService defectGroupService;

    @GetMapping("/getDetail/{defectGroupId}")
    @ApiOperation(value = "根据id获取详情", notes = "根据id获取详情")
    public ResultBody getDetail(@PathVariable String defectGroupId) {
        return defectGroupService.getDetail(defectGroupId);
    }

    @PostMapping("/queryDefectGroup")
    @ApiOperation(value = "查询缺陷组", notes = "查询缺陷组")
    public ResultBody queryDefectGroup(@RequestBody DefectGroupReq defectGroupReq) {
        return defectGroupService.queryDefectGroup(defectGroupReq);
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增缺陷组", notes = "新增缺陷组")
    public ResultBody save(@RequestBody @Valid DefectGroup defect) {
        return defectGroupService.insert(defect);
    }

    @DeleteMapping("/deleteById/{defectGroupId}")
    @ApiOperation(value = "根据id删除缺陷组", notes = "根据id删除缺陷组")
    public ResultBody deleteById(@PathVariable String defectGroupId) {
        defectGroupService.deleteById(defectGroupId);
        return ResultBody.success();
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新缺陷组", notes = "更新缺陷组")
    public ResultBody update(@RequestBody @Valid DefectGroup defectGroup) {
        return defectGroupService.edit(defectGroup);
    }

    @GetMapping("/getCheckMachine")
    @ApiOperation(value = "获取检查机列表", notes = "获取检查机列表")
    public ResultBody  getCheckMachine() {
        return defectGroupService.getCheckMachine();
    }

}
